package ACwing.P1BasicAlgorithm.guibingpaixu;

import java.math.BigInteger;
import java.util.Scanner;

/**
 * @date:2022/10/22
 * @author:LdLtd
 * @name:逆序对的数量
 */
public class MergeSort1 {
    static final int N=100010;
    static BigInteger res=new BigInteger("-1");
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int [] q=new int[N];
        int [] t=new int[N];
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            q[i]=sc.nextInt();
        }
        System.out.println(merge_sort(q, 0, n - 1, t));
    }
    public  static  BigInteger merge_sort(int [] q,int l,int r,int [] t){
            if(l>=r) return BigInteger.valueOf(0);
            int mid=l+r>>1;
            res=merge_sort(q,l,mid,t).add(merge_sort(q,mid+1,r,t));

            //归并
        int k =0,i=l,j=mid+1;
        while(i<=mid&&j<=r){
            if(q[i]<=q[j]) t[k++]=q[i++];
            else{
                t[k++]=q[j++];
                res=res.add(BigInteger.valueOf(mid-i+1));
            }
        }
            //扫尾
            while(i<=mid) t[k++]=q[i++];
            while(j<=r) t[k++]=q[j++];
                //放回
            for(i=l,j=0;i<=r;i++,j++){
                q[i]=t[j];
            }


        return  res;
}

    }